package com.su.gulimall.search.controller;

import com.su.gulimall.search.service.MallSearchService;
import com.su.gulimall.search.vo.SearchParam;
import com.su.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;
    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request)
    {
        //第一步，定义一个实体类去封装前端传递过来的参数

        //第二步，根据条件去查询出来所有满足条件的信息
        param.set_queryString(request.getQueryString());
        SearchResult result=mallSearchService.search(param);
       // 第三步，将结果存储在model中，等待视图渲染，并返回相应视图
        model.addAttribute("result",result);
        return "list";
    }

}
